package ca.jsbr.as2js_lib.utils.geom 
{
	import flash.geom.Rectangle;
	/**
	 * ...
	 * @author jsbr [me@jsbr.ca]
	 */
	public class Rect 
	{
		private var _x:int;
		private var _y:int;
		private var _width:int;
		private var _height:int;
		
		public function Rect(x:int=0,y:int=0,width:int=0,height:int=0) 
		{
			_height = height;
			_width = width;
			_y = y;
			_x = x;
			
		}
		
		
		public function merge(rect:Rect):Rect
		{
			return new Rect(_x < rect.x?_x:rect.x, _y < rect.y?_y:rect.y, _width > rect.width?_width:rect.width, _height > rect.height?_height:rect.height);
		}
		
		public function intersects(rect:Rect):Boolean
		{
			return ! ( this.left > rect.right	|| this.right < rect.left	|| this.top > rect.bottom	|| this.bottom < rect.top);
		}
		
		public function get x():int 
		{
			return _x;
		}
		
		public function set x(value:int):void 
		{
			_x = value;
		}
		
		public function get y():int 
		{
			return _y;
		}
		
		public function set y(value:int):void 
		{
			_y = value;
		}
		
		public function get width():int 
		{
			return _width;
		}
		
		public function set width(value:int):void 
		{
			_width = value;
		}
		
		public function get height():int 
		{
			return _height;
		}
		
		public function set height(value:int):void 
		{
			_height = value;
		}
		
		public function get left():int 
		{
			return x;
		}

		public function get right():int 
		{
			return x + _width;
		}
		
		public function get top():int 
		{
			return y;
		}
		
		public function get bottom():int 
		{
			return y+_height;
		}
		
	}

}